package org.esk.dablog.service.spi;

import org.esk.dablog.model.entries.Ride;
import org.esk.dablog.dao.RideDAO;
import org.esk.dablog.service.RideManager;
import org.apache.commons.lang.time.DateUtils;

import java.util.List;
import java.util.Date;
import java.util.Calendar;

/**
 * This class implements Ride-specific business logic
 * User: esk
 * Date: 09.12.2006
 * Time: 21:51:50
 * $Id:$
 */
public class RideManagerImpl implements RideManager {
    private RideDAO rideDAO;

    /**
     * returns list of active (not cancelled) rides
     * @return
     */
    public List<Ride> listActiveRidesByDate(Date d) {
        Calendar start = Calendar.getInstance();
        start.setTime(d);
        DateUtils.truncate(start, Calendar.DAY_OF_MONTH);
        Calendar end = (Calendar) start.clone();
        end.add(Calendar.DAY_OF_MONTH, 1);
        end.add(Calendar.SECOND, -1);

        return rideDAO.listActiveRidesByDate(start.getTime(), end.getTime());
    }


    public void setRideDAO(RideDAO rideDAO) {
        this.rideDAO = rideDAO;
    }
}
